<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>疫苗固有信息管理</title>
<meta name="decorator" content="default"/>
<script src="${ctxStatic}/common/change/change.js"></script>
<script src="${ctxStatic}/common/check/check.js"></script>
<script type="text/javascript">
    top.$.jBox.tip.mess=0;
	$(document).ready(function() {
		$("#inputForm").validate({
			submitHandler: function(form){
				postOrderDetil(form);
			}
		});
		
		initVaccNameInfo(bsVaccineBatchno.companyCode,bsVaccineBatchno.vaccineId);
		$("#vaccineId").change(function(){
			initCompanyNameInfo($(this).val());
			$("#vid").val("");
		});
		$("#companyCode").change(function(){
			var vaccineId = $("#vaccineId").val();
			var companyCode = $(this).val();
			if (vaccineId!=''&&companyCode!=''){
				open(vaccineId,companyCode);
			}
		});

		$("#inoculation").val(bsVaccineBatchno.inoculation).select2();
		$("#entrance").val(bsVaccineBatchno.entrance).select2();
		
		$("#batchno").blur(function(){
			if (checkBatchno()){
				check();
			}
		});
		
		$("#batchno1").blur(function(){
			check();
		});
		
		$("#btnDown").click(function(){
			$("#downForm").submit();
			layer.msg('正在下载', {icon: 1});
		});
		$("#btnDdelete").click(function(){
			layer.confirm('确定删除？', {
				btn : [ '确认', '取消' ]
			//按钮
			},function() {
				$("#deletePdf").submit();
				layer.msg('正在删除', {icon: 1});
			});
		});
		
		setTimeout(function () {
			layer.open({
				anim: 2,
				title:'批号维护须知',
				btn: '知道了',
				shade: 0,
				offset: 'rb', //右下角弹出
				type: 2,
				maxmin: true,
				area: ['600px', '400px'],
				content: '${ctx}/vaccinate/bsVaccineBatchno/notice'
			});
		}, 1000);
	});
	
	var bsVaccineBatchno = JSON.parse('${fns:toJson(bsVaccineBatchno)}');
	
	function postOrderDetil(form) {//表单保存时  将此方法中的数据尽行保存
		var companyName = $("#companyCode").find("option:selected").text();
		$("#businessName").val($("#vaccineName").val());
		$("#companyName").val(companyName);
		if(!checkBatchno()){
			layer.msg('批号重复，请检查录入数据是否有误！');
			return;
		}
		if (!check()) {
			layer.msg('确认批号不正确，请检查录入数据是否有误！');
			return;
		}
		layer.confirm('确定保存？', {
			btn : [ '保存', '取消' ]
		//按钮
		}, function() {
			layer.load(2);
			loading('正在提交，请稍等...');
			form.submit();
		});
	}

	function open(){
		$("div[data-line=line1]").find("span[data=add]").text("正在查询中...");
		var height = window.screen.height - 600;
		var width = window.screen.width -800;
		var vaccineId= $("#vaccineId").val();
		var companyCode = $("#companyCode").val();
		var  url = "${ctx}/vaccinate/bsVaccineInfo/getList?vaccineId="+vaccineId+"&companyCode="+companyCode;
		    layer.open({
	        type: 2,
	        title: '',
	        shadeClose: true,
	        skin: 'layui-layer-rim',
	        shade: 0.8,
	        closeBtn:true,
	        resize:false,
	        area: [width+"px", height+"px"],
	        content: url
      	});
	}
	
	
	function closeIframe(){
		var index = parent.layer.getFrameIndex(window.name);
		if(index){
			parent.layer.close(index);
		}else{
			window.location.href = "${ctx}/company/bsVaccineCompany/companyBatchno?batchType=1";
		}
	}
	
	function addInfo(info){
		$("#vid").val(info.id);
		$("#spec").val(info.spec);//规格
		$("#doseType").val(info.doseType1);//剂型
		$("#largePackage").val(info.largePackage);//大包装
		$("#dose").val(info.dose);					//剂量
		$("#containerType").val(info.containerTypeNam1);//容器类型
		$("#customBillNo").val(info.customBillNo);//批准文号
		$("#vaccNameAll").val(info.vaccNameAll); //疫苗全称
		$("#vaccineName").val(info.vaccName);//疫苗简称 
		$("#type").val(info.type);//
		$("div[data-line=line1]").find("span[data=add]").text("已查询");
	}
	
	function rese(){			
		location.reload();
	}
	
	function checkBatchno(){
		if($("#batchno").val()!= $("#batchnoOld").val() 
				|| $("#companyCode").val() != $("#companyCodeOld").val() 
				|| $("#vaccineId").val() != $("#vaccineIdOld").val()){
			var url = "${ctx}/vaccinate/bsVaccineBatchno/checkBatchno";
			var flag =false;
			$.ajax({
				url :url,
				async: false,
				data :{"batchno":$("#batchno").val(),
                       "vaccineId":$("#vaccineId").val(),
                       "companyCode":$("#companyCode").val()
                       },
				success : function(data){
					if(data.length>0){
						$("#batchno").nextAll("label[data=update]").text("该批次已存在!").show();
					}else{
						$("#batchno").nextAll("label[data=update]").text("").hide();
						flag = true;
					}
				}
			});
			return flag;
		}else{
			$("#batchno").nextAll("label[data=update]").text("").hide();
			return true;
		}
	}
	
	function check(){
		var batchno1 =$("#batchno1").val();
		var batchno =$("#batchno").val();
		if($("#batchno").val()==""){
			$("#batchno").nextAll('label[data=update]').text("请输入批次号!").show();
			return false;
		}
		if(batchno1 != batchno){
			$("#batchno1").nextAll('label[data=update]').text("批次号不一致，请重新输入!").show();
			return false;
		}else{
			$("#batchno1").nextAll('label[data=update]').text("").hide();
			return true;
		}
	}
</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active">
			<a >修改疫苗批次号</a>
		</li>
	</ul>
	<br/>
	<form:form id="inputForm" action="${ctx}/company/bsVaccineCompany/saveCompany"
		 modelAttribute="bsVaccineBatchno" method="post" class="form-horizontal" enctype="multipart/form-data">
	<form:input type="hidden" id="id" path="id"/>
	<form:input type="hidden" id="vid" path="vid"/>
	<form:input type="hidden" path="type" id="type" />
	<form:input type="hidden" path="batchType" id="batchType" />
	<form:input type="hidden" id="createOrgCode" path="createOrgCode"/>
	<form:input type="hidden" id="createOrgName" path="createOrgName"/>
	<form:input type="hidden" id="businessName" path="businessName"/>
	<form:input type="hidden" id="companyName" path="companyName"/>
	<input type="hidden" id="batchnoOld" name="batchnoOld" value="${bsVaccineBatchno.batchno}"/>
	<input type="hidden" id="vaccineIdOld" name="vaccineIdOld" value="${bsVaccineBatchno.vaccineId}"/>
	<input type="hidden" id="companyCodeOld" name="companyCodeOld" value="${bsVaccineBatchno.companyCode}"/>
	<input type="hidden" id="vaccineId" name="vaccineId" value="${bsVaccineBatchno.vaccineId}"/>
	<sys:message content="${message}"/>
	<div class="container-fluid">

	<div class="row-fluid">
		<div class="control-group span6 minWidth" data-line="line1">
			<label class="control-label"><font color="red">*</font> 疫苗名称：</label>
			<div class="controls">
			<select id="vaccineId" name="vaccineId" class="span7 required vaccineCompany" disabled> </select>
			<span class="help-inline" data="add"></span>
			</div>
		</div>
		
		<div class="control-group span6 minWidth" data-line="line2">
			<label class="control-label"><font color="red">*</font> 生产企业：</label>
			<div class="controls">
			<select id="companyCode" name="companyCode" class="span7 required selectCompany" disabled> </select>
			</div>
		</div>
	</div>	
	<div class="row-fluid">
	    <div class="control-group span6 minWidth">
			<label class="control-label">疫苗简称：</label>
			<div class="controls">
				<input type="text" id="vaccineName" name="vaccineName" class="span7" value="${bsVaccineBatchno.vaccineName}"/>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label">疫苗全称：</label>
			<div class="controls">
				<input type="text" id="vaccNameAll" name="vaccNameAll" class="span7" value="${bsVaccineBatchno.vaccNameAll}"/>
			</div>
		</div>
	</div>
	<div class="row-fluid">
		<div class="control-group span6 minWidth">
			<label class="control-label">规格：</label>
			<div class="controls">
				<input type="text" id="spec" name="spec" class="span7 digits" value="${bsVaccineBatchno.spec}"/>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label">批准文号：</label>
			<div class="controls">
				<input type="text" id="customBillNo" name="customBillNo" class="span7" value="${bsVaccineBatchno.customBillNo}"/>
			</div>
		</div>
	</div>
	
	<div class="row-fluid">
		<div class="control-group span6 minWidth">
			<label class="control-label"><font color="red">*</font> 批号：</label>
			<div class="controls">
				<input type="text" id="batchno" name="batchno" maxlength="20" class="span7 required"  value="${bsVaccineBatchno.batchno}" />
				<label hidden="true"  class="error" data="update"></label>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label"><font color="red">*</font> 确认批号：</label>
			<div class="controls">
				<input type="text" id="batchno1" name="batchno1" maxlength="20" class="span7 required" value="${bsVaccineBatchno.batchno}"/>
				<label hidden="true"  class="error" data="update"></label>
			</div>
		</div>
	</div>


	<div class="row-fluid">
		<div class="control-group span6 minWidth">
			<label class="control-label"><abbr title="(暂时不需要录入)">亚批号：</abbr></label>
			<div class="controls">
				<input type="text" id="secondBatchno" name="secondBatchno"  maxlength="32" class="span7"  value="${bsVaccineBatchno.secondBatchno}"/>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label"><font color="red">*</font> 有效日期至：</label>
			<div class="controls">
				<input id="outBoundDate" name="outBoundDate" type="text" maxlength="20" class="span7 Wdate required"
				value="<fmt:formatDate value="${bsVaccineBatchno.outBoundDate}" pattern="yyyy-MM-dd"/>"
				onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
			</div>
		</div>
	</div>	
	
	<div class="row-fluid">
		<div class="control-group span6 minWidth">
			<label class="control-label">大包装(支(粒)/箱)：</label>
			<div class="controls">
				<input type="text" id="largePackage" name="largePackage"  
				maxlength="32" class="span7" value="${bsVaccineBatchno.largePackage}"/>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label"><font color="red">*</font>最小分包装(支(粒)/盒)：</label>
			<div class="controls">
				<input type="text" id="smallPackage" name="smallPackage" maxlength="32" value="${bsVaccineBatchno.smallPackage}" class="span7 digits required"/>
			</div>
		</div>
	</div>
	<div class="row-fluid">	
		<div class="control-group span6 minWidth">
			<label class="control-label">剂型：</label>
			<div class="controls">
				<input type="text" id="doseType" name="doseType" 
				maxlength="32" class="span7" value="${bsVaccineBatchno.doseType}"/>
			</div>
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label">剂量：</label>
			<div class="controls">
				<input type="text" id="dose" name="dose" 
				maxlength="32" class="span7" value="${bsVaccineBatchno.dose}"/>
			</div>
		</div>
	</div>
	<div class="row-fluid">	
		<div class="control-group span6 minWidth">
			<label class="control-label">接种途径：</label>
			<div class="controls">
				<select id="inoculation" name="inoculation" class="span7">
					<option value="">-请选择-</option>
					<c:forEach items="${fns:getDictList('inoculation_route')}" var="dict">
						<option value="${dict.value}">${dict.label}</option>
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="control-group span6 minWidth">
			<label class="control-label">是否为进口疫苗：</label>
			<div class="controls">
			<select  id="entrance" name="entrance" class="span7">
				<option value="">-请选择-</option>
				<option value="1">是</option>
				<option value="0">否</option>
			</select>
		</div>
		</div>
	</div>	
	<div class="row-fluid">	
	    <div class="control-group span6 minWidth">
			<label class="control-label">批签发合格证明编号：</label>
			<div class="controls">
				<input type="text"  id="certifiCode" name="certifiCode" 
				maxlength="32" class="span7" value="${bsVaccineBatchno.certifiCode}"/>
			</div>
		</div>
		<div class="control-group span6 minWidth">
			<label class="control-label">进口通关单编号：</label>
			<div class="controls">
				<input type="text"  id="code"  name="code" maxlength="32" class="span7" value="${bsVaccineBatchno.code}"/>
			</div>
		</div>
	</div>	
	<div class="row-fluid">	
	    <div class="control-group span6 minWidth">
			<label class="control-label">批签发合格证明文件：</label>
			<div class="controls">
				<input type="file"  id="pdfFile" name="pdfFile" class="input-mini" onchange="checkFile(this);"/>
				<span style="color:red;font-size:6px;font-style:italic;">*可上传的类型有PDF,JPG,PNG,JPEG</span>
				<c:if test="${not empty bsVaccineBatchnoPdf}">
				    <br><a href="${ctx}/vaccinate/bsVaccineBatchno/downPdf?id=${bsVaccineBatchnoPdf.id}">${bsVaccineBatchnoPdf.fileName}</a>
					<c:if test="${office.code == bsVaccineBatchnoPdf.createOrgCode && not empty bsVaccineBatchnoPdf.id}">
					    <span><button id="btnDdelete" class="btn btn-primary" type="button" >删除原文件</button></span>
					</c:if>
				</c:if>
			</div> 
		</div>
		
		<div class="control-group span6 minWidth">
			<label class="control-label">容器类型：</label>
			<div class="controls">
				<input type="text" id="containerType" name="containerType"  
				maxlength="255" class="span7" value="${bsVaccineBatchno.containerType}"/>
			</div>
		</div>
	</div>	
	<div class="form-actions">
		<button id="btnSubmit" class="btn btn-primary" type="submit" >保存</button>
		<button id="btnReset" class="btn" type="button" onclick = "rese()">重置</button>
		<button id="btnClose" class="btn" type="button" onclick="closeIframe()">关闭</button>
	</div>
	</div>
	</form:form>
	
	<form id="downForm" action="${ctx}/company/bsVaccineCompany/downPdf" method="post">
		<input type="hidden" id="id" name="id" value = "${bsVaccineBatchnoPdf.id}"/>
	</form>
	
	<form id="deletePdf" action="${ctx}/company/bsVaccineCompany/deletePdf" method="post">
		<input type="hidden" id="pdfId" name="pdfId" value = "${bsVaccineBatchnoPdf.id}"/>
		<input type="hidden" id="id" name="id" value = "${bsVaccineBatchno.id}"/>
	</form>
</body>
</html>